home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / PCMAP.ASM < prev    next >
Assembly Source File  |  1989-04-22  |  39KB  |  1,105 lines

  1.  
  2. page 58,132
  3.  
  4. ;----------------------------------------------------------------
  5. ; PCMAP 2.0 - Jeff Hasty (CompuServe 71121,2352) - April, 1989
  6. ;         Documentation in PCMAP2.DOC
  7. ;----------------------------------------------------------------
  8.  
  9. ;----------------------------------------------------------------
  10. ; EQUATES
  11. ;----------------------------------------------------------------
  12. MAX_BLK     EQU    23        ;Number of spaces in table
  13. INT9_BUSY    EQU    1        ;Mask for BUSY byte
  14. INT10_BUSY    EQU    2        ;Mask for BUSY byte
  15. SHIFT_MASK    EQU    8        ;Mask for hot key (8=Alt)
  16. HOTKEY        EQU    19H        ;Scan code (19h=P)
  17.  
  18. CR        EQU    0DH        ; ASCII carriage return
  19. LF        EQU    0AH        ; ASCII line feed
  20. TAB        EQU    09h        ; ASCII tab
  21. BLANK        EQU    20h        ; ASCII space character
  22.  
  23. ;----------------------------------------------------------------
  24. ; START - entry point for command-line mode
  25. ;----------------------------------------------------------------
  26. _TEXT    SEGMENT PARA    PUBLIC    'CODE'    ;set up for .COM file
  27.     ASSUME    CS:_TEXT,DS:_TEXT
  28.         ORG 100H
  29. START:
  30.         JMP    RES        ;jump to installation routines
  31.  
  32. ;----------------------------------------------------------------
  33. ; RESIDENT DATA AREA
  34. ;----------------------------------------------------------------
  35. ID        DB    "PCMAP 2.0 - Jeff Hasty (CompuServe 71121,2352)"
  36.         DB    " - April, 1989",1Ah
  37. HEADING_MSG    DB    CR,LF
  38.                 DB      "Segment               Size                 Program"
  39.                 DB      CR,LF
  40.                 DB      "Address    Owner      (para)     Type      Name"
  41.         DB    CR,LF
  42.         DB    "0000",18 DUP(' '),0
  43. BLOCK1_MSG    DB    10 DUP (' '),"DOS + Drivers",CR,LF,0
  44. CR_LF_MSG    DB    CR,LF,0
  45. COM_MSG         DB      "COMMAND.COM"
  46. PSP_MSG         DB      "PSP"
  47. ENV_MSG         DB      "ENV"
  48. UNK_MSG         DB      "(Unknown)"
  49. FREE_MSG        DB      "(Free)"
  50. SPACE3_MSG      DB      "   "
  51. SPACE_MSG    DB    7 DUP(' '),0
  52. TABLE_FULL_MSG    DB    "Out of space     ",0
  53. PROGRAM_ID    DB    "PCMAP 2.0",0
  54. HIT_ANY_KEY    DB    "  -  Hit any key to return...",0
  55.  
  56. DISABLE     DB    0    ;flag to disable if cannot uninstall
  57. TSR_MODE    DB    1    ;=0 if command line mode
  58. VER3        DB    0    ;=1 if Version >= 3.0
  59. LAST_BLOCK    DB    0    ;=1 if last MCB
  60. TABLE_FULL    DB    0    ;=1 if table full
  61.  
  62. CURSOR_POS    DW    0    ;to store cursor position
  63. BIOS_SEG    DW    40H    ;address of bios data area
  64. DIFF        DW    0    ;# of chars on a line > 80
  65. N_BLK        DB    0    ;Count table entries
  66.  
  67. OUR_SS        DW    0    ;  used for stack swap
  68. OUR_SP        DW    0
  69. THEIR_SS    DW    0
  70. THEIR_SP    DW    0
  71. RETADDR     DW    0
  72.  
  73. ADDR_INT9H    DD    0    ;to save original vectors
  74. ADDR_INT10H    DD    0
  75. BUSY        DB    0    ;to store status of int 9 and int 10h
  76.  
  77. ;----------------------------------------------------------------------
  78. ; INT9H - entry point for memory-resident mode.
  79. ; pressing any key causes entry here.
  80. ;----------------------------------------------------------------------
  81. INT9H PROC FAR
  82.         STI                ;interrupts on
  83.         PUSH    AX            ;save working register
  84.         CMP    CS:DISABLE,-1        ;if disabled, do nothing
  85.         JE    NOT_US
  86.         IN    AL,60H            ;get key from keyboard port
  87.         CMP    AL,HOTKEY        ;is it our hotkey?
  88.         JNE    NOT_US            ;if not, exit
  89.         MOV    AH,2            ;otherwise
  90.         INT    16H            ;get shift status
  91.         AND    AL,0FH
  92.         CMP    AL,SHIFT_MASK        ;test the shift status
  93.         JNE    NOT_US            ;if not shift combo, exit
  94.         IN    AL,61H            ;These instructions reset
  95.         MOV    AH,AL            ; the keyboard.
  96.         OR    AL,80H
  97.         OUT    61H,AL
  98.         MOV    AL,AH
  99.         JMP    SHORT $+2        ;I/O delay for fast AT's
  100.         OUT    61H,AL
  101.         CLI                ;Disable interrupts and
  102.         MOV    AL,20H            ;reset the int controller
  103.         OUT    20H,AL
  104.         STI
  105.         CMP    CS:BUSY,0        ;recursion protection
  106.         JNE    WE_ARE_BUSY        ;dont allow re-entrancy
  107.         OR    CS:BUSY,INT9_BUSY    ;set flag for protection
  108.         CALL    ADJUST_FOR_VIDEO_MODE
  109.         JC    CANT_POP_UP        ;exit if inappropriate mode
  110.         CALL    MAIN            ;call our program
  111. CANT_POP_UP:
  112.         CLI                ;disable kbd momentarily
  113.         AND    CS:BUSY,NOT(INT9_BUSY)    ;reset protection
  114. WE_ARE_BUSY:
  115.         POP    AX            ;restore working register
  116.         STI
  117.         IRET                ;return to foreground
  118. NOT_US:
  119.         POP    AX            ;restore working register
  120.         CLI                ;interrupts off
  121.         JMP    CS:ADDR_INT9H        ;jump to original int 9
  122. INT9H ENDP
  123.  
  124.  
  125. ;-----------------------------------------------------------------
  126. ; ADJUST_FOR_VIDEO_MODE
  127. ; check for text modes and set offset for lines > than 80 characters
  128. ; in length.  sets carry flag if inappropriate mode for pop-up.
  129. ;-----------------------------------------------------------------
  130. ADJUST_FOR_VIDEO_MODE PROC NEAR
  131.  
  132.         PUSH    BX            ;save register
  133.         MOV    AH,15            ;get present mode
  134.         INT    10H
  135.  
  136.         CMP    AH,80
  137.         JB    BAD_MODE        ;less than 80 chars per line
  138.  
  139.         MOV    CS:BYTE PTR DIFF,AH    ;calc the # of chars > 80
  140.         SUB    CS:BYTE PTR DIFF,80    ;on the line & save in diff
  141.         CMP    AL,7            ;7 is mono, good mode
  142.         JNE    TRY_COLOR
  143. MODE_OK:
  144.         CLC                ;clear carry flag
  145.         POP    BX            ;restore register
  146.         RET
  147. TRY_COLOR:
  148.         CMP    AL,3            ;3 is color 80x25,
  149.         JBE    MODE_OK         ;  2 is B&W 80x25
  150. BAD_MODE:
  151.         STC                ;not good mode, set carry flag
  152.         POP    BX            ;restore register
  153.         RET
  154.  
  155. ADJUST_FOR_VIDEO_MODE ENDP
  156.  
  157. ;-----------------------------------------------------------------
  158. ; MAIN - main routine called by pressing hot key
  159. ;-----------------------------------------------------------------
  160. MAIN PROC NEAR
  161.         CLD                ;strings forward
  162.         CALL    SWAPIN            ;new stack
  163.         MOV    AX,CS            ;our data segment is
  164.         MOV    DS,AX            ;  same as CS
  165.         CALL    GETPOS            ;save cursor position
  166.         CALL    CURSOR_HOME        ;cursor to 0,0
  167.         CALL    SAVE_SCREEN        ;save screen
  168.         CALL    CLEAR_SCREEN        ;clear screen
  169.         CALL    PROGRAM         ;construct & display memory map
  170.         MOV    TABLE_FULL,0        ;reset flag
  171.         CALL    RESTORE_SCREEN        ;put screen back
  172.         CALL    RESTORE_CURSOR        ;cursor to original position
  173.         CALL    SWAPOUT            ;put stack back
  174.         RET                ;that's all
  175. MAIN ENDP
  176.  
  177.  
  178. ;-----------------------------------------------------------------
  179. ; SWAPIN, SWAPOUT - stack routines
  180. ;-----------------------------------------------------------------
  181. SWAPIN PROC NEAR
  182.         POP    CS:RETADDR        ;save callers address
  183.         MOV    CS:THEIR_SS,SS        ;save their stack
  184.         MOV    CS:THEIR_SP,SP
  185.         MOV    SS,CS:OUR_SS        ;switch to our stack
  186.         MOV    SP,CS:OUR_SP
  187.         PUSH    AX            ;save all registers
  188.         PUSH    BX
  189.         PUSH    CX
  190.         PUSH    DX
  191.         PUSH    SI
  192.         PUSH    DI
  193.         PUSH    ES
  194.         PUSH    DS
  195.         PUSH    BP
  196.         JMP    CS:RETADDR        ;return to caller
  197. SWAPIN ENDP
  198. ;-----------------------------------------------------------------
  199. SWAPOUT PROC NEAR
  200.         POP    CS:RETADDR        ;save callers address
  201.         POP    BP            ;restore all registers
  202.         POP    DS
  203.         POP    ES
  204.         POP    DI
  205.         POP    SI
  206.         POP    DX
  207.         POP    CX
  208.         POP    BX
  209.         POP    AX
  210.         MOV    SS,CS:THEIR_SS        ;restore callers stack
  211.         MOV    SP,CS:THEIR_SP
  212.         JMP    CS:RETADDR        ;return to caller
  213. SWAPOUT ENDP
  214.  
  215. ;-----------------------------------------------------------------
  216. ; GETPOS, CURSOR_HOME, RESTORE_CURSOR, SETPOS - cursor routines
  217. ;-----------------------------------------------------------------
  218. GETPOS PROC NEAR
  219.         MOV    AH,3            ;get cursor position
  220.         XOR    BH,BH            ;active page
  221.         INT    10H            ;get cursor position in dx
  222.         MOV    CURSOR_POS,DX        ;  and save
  223.         RET
  224. GETPOS ENDP
  225. ;----------------------------------------------------------------------
  226. CURSOR_HOME    PROC    NEAR
  227.         XOR    DX,DX            ;position 0,0
  228.         CALL    SETPOS            ;set cursor position
  229.         RET
  230. CURSOR_HOME    ENDP
  231.  
  232. ;----------------------------------------------------------------------
  233. RESTORE_CURSOR PROC NEAR
  234.         MOV    DX,CURSOR_POS        ;saved position
  235.         CALL    SETPOS            ;set
  236.         RET
  237. RESTORE_CURSOR ENDP
  238. ;----------------------------------------------------------------------
  239. SETPOS PROC NEAR
  240.         MOV    AH,2            ;set cursor position
  241.         XOR    BH,BH            ;active page
  242.         INT    10H            ;set cursor position to dx
  243.         RET
  244. SETPOS ENDP
  245.  
  246. ;-----------------------------------------------------------------
  247. ; SAVE_SCREEN, CLEAR_SCREEN, RESTORE_SCREEN - screen routines
  248. ;-----------------------------------------------------------------
  249. SAVE_SCREEN PROC NEAR
  250.         PUSH    DS            ;save data segment
  251.         XOR    AX,AX
  252.         MOV    BX,AX
  253.         CALL    CALC_SCRN_ADDR        ;address of (0,0)
  254.         MOV    SI,OFFSET SCREEN    ;buffer is past end of table
  255.         PUSH    DS            ;exchange
  256.         PUSH    ES            ;ds and es
  257.         POP    DS
  258.         POP    ES
  259.         XCHG    DI,SI            ;exchange source,destination
  260.         MOV    BX,25            ;save 25 lines
  261. SAVE_NEXT_LINE:
  262.         MOV    CX,80            ;save 80 words per line
  263.         REP    MOVSW            ;save line
  264.         ADD    SI,CS:DIFF        ;add extra characters and
  265.         ADD    SI,CS:DIFF        ;  attributes to SI
  266.         DEC    BX            ;d